from sqlalchemy import Column, VARCHAR, DATETIME, INT, Text, Integer, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.expression import column

Base = declarative_base()


class ShopModel(Base):
    __tablename__ = 'shop'

    id = Column(Integer, primary_key=True)
    shop_name = Column(VARCHAR)
    shop_id = Column(Integer)
    shop_url = Column(VARCHAR)
    shop_log = Column(VARCHAR)
    shop_type = Column(INT)

    company_telphone = Column(VARCHAR)
    company_address = Column(VARCHAR)
    company_name = Column(VARCHAR)

    country = Column(VARCHAR)
    province = Column(VARCHAR)
    city = Column(VARCHAR)
    area = Column(VARCHAR)

    screen_shot = Column(VARCHAR)
    status = Column(INT)
    

    create_time = Column(DATETIME)

    def keys(self):
        return (
          'id',
          'shop_name',
          'shop_id',
          'shop_url',
          'shop_log',
          'shop_type',
          'company_telphone',
          'company_address',
          'company_name',
          'country',
          'province',
          'city',
          'area',
          'screen_shot',
          'status',
          'create_time',
        )

    def __getitem__(self, item):
        return getattr(self, item)


class ProductModel(Base):
    __tablename__ = 'product'

    id = Column(Integer, primary_key=True)

    product_name = Column(VARCHAR)
    product_url = Column(Integer)
    product_id = Column(VARCHAR)
    product_price = Column(Integer)
    product_classify = Column(VARCHAR)
    product_desc = Column(VARCHAR)
    product_screenshot = Column(VARCHAR)
    product_img = Column(VARCHAR)

    shop_id = Column(Integer)

    create_time = Column(DATETIME)

    def keys(self):
        return (
            'id',
            'product_name',
            'product_url',
            'product_id',
            'product_price',
            'product_classify',
            'product_desc',
            'product_screenshot',
            'product_img',
            'create_time',
        )

    def __getitem__(self, item):
        return getattr(self, item)


class Company(Base):
    __tablename__ = 'company'

    id = Column(Integer, primary_key=True)

    name = Column(VARCHAR)
    platform_type = Column(VARCHAR)
    platform_id = Column(VARCHAR)
    legal_representative = Column(VARCHAR)
    management_forms = Column(VARCHAR)
    register_date = Column(VARCHAR)
    registered_capital = Column(VARCHAR)
    contributed_capital = Column(VARCHAR)
    b_code = Column(VARCHAR)
    u_code = Column(VARCHAR)
    t_code = Column(VARCHAR)
    o_code = Column(VARCHAR)
    business_term = Column(VARCHAR)
    taxpayer_qualification = Column(VARCHAR)
    approval_date = Column(VARCHAR)
    company_type = Column(VARCHAR)
    industry = Column(VARCHAR)
    staff_size = Column(VARCHAR)
    registration_authority = Column(VARCHAR)
    registered_address = Column(VARCHAR)
    registered_status = Column(VARCHAR)
    business_scope = Column(VARCHAR)
    shop_id = Column(Integer)

    create_time = Column(DATETIME)

    def keys(self):
        return (
          'id',
          'name', 
          'platform_type', 
          'platform_id', 
          'legal_representative', 
          'management_forms', 
          'register_date', 
          'registered_capital', 
          'contributed_capital', 
          'b_code', 
          'u_code', 
          't_code', 
          'o_code', 
          'business_term', 
          'taxpayer_qualification', 
          'approval_date', 
          'company_type', 
          'industry', 
          'staff_size', 
          'registration_authority', 
          'registered_address', 
          'registered_status', 
          'business_scope', 
          'shop_id',

          'create_time' 
        )

    def __getitem__(self, item):
        return getattr(self, item)

    def __setattr__(self, name, value) -> None:
        return super().__setattr__(name, value)
